package com.ttxs.fileformathandling.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ttxs.apicommon.model.entity.Api;
import com.ttxs.fileformathandling.common.ErrorCode;
import com.ttxs.fileformathandling.exception.BusinessException;

import com.ttxs.fileformathandling.service.ApiService;
import com.ttxs.fileformathandling.mapper.ApiMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @author cwt
 * @description 针对表【api(接口表)】的数据库操作Service实现
 * @createDate 2023-06-07 22:39:12
 */
@Service
public class ApiServiceImpl extends ServiceImpl<ApiMapper, Api>
        implements ApiService {



    @Override
    public void validApi(Api api, boolean add) {
        if (api == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        String name = api.getName();
        String url = api.getUrl();
        String method = api.getMethod();
        String requestParams = api.getRequestParams();
        if (add) {
            if (StringUtils.isAnyBlank(name, url, method, requestParams)) {
                throw new BusinessException(ErrorCode.PARAMS_ERROR, "参数不能为空");
            }
        }
        if (StringUtils.isNotBlank(name) && name.length() > 50) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "接口名称过长");
        }
    }
}




